package presentacion;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import java.awt.Frame;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import java.awt.Color;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JScrollPane;
import java.awt.Font;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import java.awt.Component;
import javax.swing.SwingConstants;

public class AAAAAAAdocente extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JPanel contentPane;
	private JTable table;


	public AAAAAAAdocente(String nombreDeUsuario) {
		
		setTitle("Campus Virtual");
		setExtendedState(Frame.MAXIMIZED_BOTH);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		
		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);
		
		JMenu mnNewMenu = new JMenu("Cursos");
		menuBar.add(mnNewMenu);
		
		JMenuItem mntmVisualizarCusosDicatados = new JMenuItem("Visualizar cusos dicatados");
		
	
		
		
		mnNewMenu.add(mntmVisualizarCusosDicatados);
		
		JMenu mnEvaluacin = new JMenu("Evaluaci\u00F3n");
		menuBar.add(mnEvaluacin);
		
		JMenuItem mntmCrear = new JMenuItem("Crear");
		mnEvaluacin.add(mntmCrear);
		
		JMenuItem mntmColocarNota = new JMenuItem("Colocar Nota");
		mnEvaluacin.add(mntmColocarNota);
		
		JMenu mnTarea = new JMenu("Tarea");
		menuBar.add(mnTarea);
		
		JMenuItem mntmCrear_1 = new JMenuItem("Crear");
		mnTarea.add(mntmCrear_1);
		
		JMenuItem mntmColocarNota_1 = new JMenuItem("Colocar nota");
		mnTarea.add(mntmColocarNota_1);
		
		JMenu mnCuenta = new JMenu("Cuenta");
		menuBar.add(mnCuenta);
		
		JMenuItem mntmConfigurarCuenta = new JMenuItem("Configurar Cuenta");
		mnCuenta.add(mntmConfigurarCuenta);
		
		
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		
		
		final JPanel panel = new JPanel();
		panel.setAlignmentY(Component.BOTTOM_ALIGNMENT);
		
		
		JLabel lblNombreDeUsuario = new JLabel(nombreDeUsuario);
		lblNombreDeUsuario.setHorizontalAlignment(SwingConstants.RIGHT);
		
		JButton btnCerrarSesion = new JButton("Cerrar Sesion");
		btnCerrarSesion.setHorizontalAlignment(SwingConstants.RIGHT);
		
		
		
		
		
		
		//click en cerrar sesion
		btnCerrarSesion.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				
				//cerrar la venta con dispose() y talvez tenga que limpiar todo
				
				
				
				dispose();
				AAAAAAAutenticarse frame = new AAAAAAAutenticarse();
				frame.setLocationRelativeTo(null);
				frame.setVisible(true);
			}
		});
		
		
		
		
		
		
		// mensaje de errror
		
		JLabel lblMsjError = new JLabel("Msj error");
		lblMsjError.setForeground(Color.RED);
		lblMsjError.setFont(new Font("Tahoma", Font.PLAIN, 14));
		lblMsjError.setVisible(false);
		//fin mensaje error
		
		
		
		// ---------------------------------------------------------------------------------------------------------------------------------------------------
		
		
		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane.setHorizontalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addGap(22)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
						.addGroup(gl_contentPane.createSequentialGroup()
							.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
								.addGroup(gl_contentPane.createSequentialGroup()
									.addPreferredGap(ComponentPlacement.RELATED, 201, Short.MAX_VALUE)
									.addComponent(lblNombreDeUsuario)
									.addPreferredGap(ComponentPlacement.RELATED))
								.addGroup(gl_contentPane.createSequentialGroup()
									.addComponent(lblMsjError)
									.addPreferredGap(ComponentPlacement.RELATED)))
							.addComponent(btnCerrarSesion))
						.addComponent(panel, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 392, Short.MAX_VALUE))
					.addContainerGap())
		);
		gl_contentPane.setVerticalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_contentPane.createSequentialGroup()
							.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
								.addComponent(lblNombreDeUsuario)
								.addComponent(btnCerrarSesion))
							.addPreferredGap(ComponentPlacement.RELATED))
						.addGroup(Alignment.TRAILING, gl_contentPane.createSequentialGroup()
							.addContainerGap(19, Short.MAX_VALUE)
							.addComponent(lblMsjError)
							.addPreferredGap(ComponentPlacement.RELATED)))
					.addComponent(panel, GroupLayout.PREFERRED_SIZE, 532, GroupLayout.PREFERRED_SIZE)
					.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
		);
		
		JLabel lblCursosAsociados = new JLabel("Cursos Asociados");
		lblCursosAsociados.setFont(new Font("Tahoma", Font.BOLD, 20));
		
		JScrollPane scrollPane = new JScrollPane();
		GroupLayout gl_panel = new GroupLayout(panel);
		gl_panel.setHorizontalGroup(
			gl_panel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel.createSequentialGroup()
					.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_panel.createSequentialGroup()
							.addGap(10)
							.addComponent(scrollPane, GroupLayout.DEFAULT_SIZE, 390, Short.MAX_VALUE))
						.addGroup(gl_panel.createSequentialGroup()
							.addContainerGap()
							.addComponent(lblCursosAsociados)))
					.addContainerGap())
		);
		gl_panel.setVerticalGroup(
			gl_panel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel.createSequentialGroup()
					.addComponent(lblCursosAsociados)
					.addGap(11)
					.addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 349, GroupLayout.PREFERRED_SIZE)
					.addContainerGap(147, Short.MAX_VALUE))
		);
		
		table = new JTable();
		table.setModel(new DefaultTableModel(
			new Object[][] {
				{null, null, null, null, null},
				{null, null, null, null, null},
				{null, null, null, null, null},
				{null, null, null, null, null},
				{null, null, null, null, null},
				{null, null, null, null, null},
				{null, null, null, null, null},
				{null, null, null, null, null},
				{null, null, null, null, null},
				{null, null, null, null, null},
				{null, null, null, null, null},
				{null, null, null, null, null},
				{null, null, null, null, null},
				{null, null, null, null, null},
				{null, null, null, null, null},
				{null, null, null, null, null},
				{null, null, null, null, null},
				{null, null, null, null, null},
				{null, null, null, null, null},
				{null, null, null, null, null},
				{null, null, null, null, null},
				{null, null, null, null, null},
				{null, null, null, null, null},
				{null, null, null, null, null},
				{null, null, null, null, null},
				{null, null, null, null, null},
				{null, null, null, null, null},
				{null, null, null, null, null},
				{null, null, null, null, null},
				{null, null, null, null, null},
				{null, null, null, null, null},
				{null, null, null, null, null},
				{null, null, null, null, null},
				{null, null, null, null, null},
				{null, null, null, null, null},
				{null, null, null, null, null},
				{null, null, null, null, null},
				{null, null, null, null, null},
				{null, null, null, null, null},
				{null, null, null, null, null},
				{null, null, null, null, null},
				{null, null, null, null, null},
				{null, null, null, null, null},
				{null, null, null, null, null},
				{null, null, null, null, null},
				{null, null, null, null, null},
				{null, null, null, null, null},
				{null, null, null, null, null},
				{null, null, null, null, null},
				{null, null, null, null, null},
			},
			new String[] {
				"Nombre", "Cupos", "Fecha de inicio", "Fecha de fin", "Horas totales"
			}
		));
		table.getColumnModel().getColumn(0).setPreferredWidth(230);
		table.getColumnModel().getColumn(2).setPreferredWidth(99);
		table.getColumnModel().getColumn(3).setPreferredWidth(88);
		scrollPane.setViewportView(table);
		panel.setLayout(gl_panel);
		contentPane.setLayout(gl_contentPane);
		
	

		panel.setVisible(false);
		
		
		// Click en visualaziar cursos
		mntmVisualizarCusosDicatados.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				
				//Enviar un msj al controller de docente --> cursosQueDicta(UsuarioDTO)
				
				
				panel.setVisible(true);
				
				// Cargar los cursos en la tabla
				
				DefaultTableModel md= (DefaultTableModel) table.getModel();
				Object [] fila = {"Admi de recursos","22","12/4/1100","daasd","sadsa"};
				md.addRow(fila);
				
			}
		});
	
		
		
		
	}


}
